package authorization;

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;

import org.testng.*;
import org.testng.annotations.*;

import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class Login_positive extends ru.st.selenium.pages.TestBase {
  private boolean acceptNextAlert = true;
  private StringBuffer verificationErrors = new StringBuffer();

    @Test
  public void testUntitled2() throws Exception {
    driver.get(baseUrl + "/");
    WebElement linkLogin = driver.findElement(By.linkText("Log In"));
	linkLogin.click();
    WebElement userEmail = driver.findElement(By.id("email"));
	userEmail.clear();
    userEmail.sendKeys("qatestingtestqa@gmail.com");
    WebElement userPassword = driver.findElement(By.id("pass"));
	userPassword.clear();
    userPassword.sendKeys("qwerty");
    WebElement buttonSend = driver.findElement(By.id("send2"));
	buttonSend.click();
    try {
      WebElement messageWelcome = driver.findElement(By.cssSelector("p.welcome-msg"));
	assertEquals("Welcome, test test!", messageWelcome.getText());
    } catch (Error e) {
      verificationErrors.append(e.toString());
    }
    WebElement linkLogout = driver.findElement(By.linkText("Log Out"));
	linkLogout.click();
  }

   private boolean isElementPresent(By by) {
    try {
      driver.findElement(by);
      return true;
    } catch (NoSuchElementException e) {
      return false;
    }
  }

  
  private String closeAlertAndGetItsText() {
    try {
      Alert alert = driver.switchTo().alert();
      String alertText = alert.getText();
      if (acceptNextAlert) {
        alert.accept();
      } else {
        alert.dismiss();
      }
      return alertText;
    } finally {
      acceptNextAlert = true;
    }
  }
}
